//
//  LYLTimeLineBlurView.m
//  Diary
//
//  Created by lanou3g on 15/11/10.
//  Copyright © 2015年 王艺拓. All rights reserved.
//

#import "LYLTimeLineBlurView.h"
#define kSelfViewW [UIScreen mainScreen].bounds.size.width
#define kSelfViewH [UIScreen mainScreen].bounds.size.height
#define kLocationLabelH kSelfViewH*0.038
#define kDateLabelH kSelfViewH*0.038
#define kPictureH kSelfViewH*0.4
#define kBodyH kSelfViewH*0.2
#define kEachOtherSpace kSelfViewH*0.025
#define kTopSpace kSelfViewH*0.175
#define kSpace kSelfViewH*0.025

@implementation LYLTimeLineBlurView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithEffect:(UIVisualEffect *)effect
{
    self = [super initWithEffect:effect];
    if (self) {
        self.locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kTopSpace, kSelfViewW, kLocationLabelH)];
        self.locationLabel.textAlignment = NSTextAlignmentCenter;
        self.locationLabel.textColor = [UIColor whiteColor];
        [self addSubview:self.locationLabel];
        
        self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, kTopSpace + kLocationLabelH, kSelfViewW, kLocationLabelH)];
        self.dateLabel.textAlignment = NSTextAlignmentCenter;
        self.dateLabel.textColor = [UIColor whiteColor];
        self.dateLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.dateLabel];
        
        self.pictureImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, kTopSpace + kLocationLabelH + kDateLabelH + kEachOtherSpace*2, kSelfViewW, kPictureH)];
        self.pictureImg.contentMode = UIViewContentModeScaleAspectFill;
        self.pictureImg.layer.masksToBounds = YES;
        [self addSubview:self.pictureImg];
        
        self.bodyText = [[UITextView alloc] initWithFrame:CGRectMake(kSpace, kTopSpace + kLocationLabelH + kDateLabelH + kEachOtherSpace*2 + kPictureH + kEachOtherSpace, kSelfViewW - kSpace, kBodyH)];
        self.bodyText.backgroundColor = [UIColor clearColor];
        self.bodyText.textColor = [UIColor whiteColor];
        self.bodyText.editable = NO;
        self.bodyText.showsVerticalScrollIndicator = NO;
        self.bodyText.textAlignment = NSTextAlignmentLeft;
        self.bodyText.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.bodyText];
        
        UITapGestureRecognizer *disappearTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disappearTap)];
        disappearTap.numberOfTapsRequired = 1;
        [self addGestureRecognizer:disappearTap];
    }
    return self;
}

- (void)disappearTap
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0.0f;
    }];
}

@end
